import { Router } from 'express';
import {
  getCartItems,
  addToCart,
  updateCartItem,
  deleteCartItem,
  deleteCartItems,
  clearCart,
  getSelectedCartItems,
  selectAllCartItems,
  getCartStats
} from '../controllers/cartController';
import { authenticate } from '../middleware/auth';

const router = Router();

// 获取购物车统计
router.get('/stats', authenticate, getCartStats);

// 获取选中的购物车项
router.get('/selected', authenticate, getSelectedCartItems);

// 获取购物车列表
router.get('/', authenticate, getCartItems);

// 添加商品到购物车
router.post('/', authenticate, addToCart);

// 全选/取消全选
router.post('/select-all', authenticate, selectAllCartItems);

// 批量删除购物车项
router.delete('/batch', authenticate, deleteCartItems);

// 清空购物车
router.delete('/clear', authenticate, clearCart);

// 更新购物车项
router.put('/:id', authenticate, updateCartItem);

// 删除购物车项
router.delete('/:id', authenticate, deleteCartItem);

export default router;